package com.efuture.androidmvpdemo.ui.register

import com.efuture.androidmvpdemo.ui.base.BasePresenter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel

/**

 *@description:TODO
 * @author: zhaoshanshan
 * @date: 2022/3/26 5:56 下午

 */
class RegisterPresenter(var registerView:RegisterView?,val registerInteractor:RegisterInteractor):RegisterInteractor.OnRegisterFinishedListener,BasePresenter{

    fun registerUser(mainScope: CoroutineScope, username: String, password: String){
        registerInteractor.registerUser(mainScope,username,password,this)
    }

    override fun onSuccess() {

        registerView?.registerSuccess()
        registerView?.clearInputData()

    }

    override fun onFail(reason: String) {

        registerView?.registerFail(reason)
    }

    override fun onDestroyView(mainScope: CoroutineScope) {
        registerView = null
        mainScope?.cancel()
    }
}